package com.yunweiweishi.xuhuanpaltform.yuhuan_app.controller;


import com.yunweiweishi.xuhuanpaltform.yuhuan_app.comm.conf.CommonResult;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.pojo.PatrolRoute;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.service.RouteService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(value = "线路", tags = {"线路controller"})
@RestController
@RequestMapping("route")
public class RouteController {

     @Autowired
    private RouteService routeService;

    @Autowired
    private CommonResult result;


    /**
     *根据线路名查找路路线
     * @param patrolName
     * @return
     */
    @GetMapping("/findRouteByRouteName")
    public CommonResult findRouteByRouteName(@RequestParam("patrolName") String patrolName) {


        try {
            PatrolRoute patrolRoute = routeService.findRouteByRouteName(patrolName);
           result.setData(patrolRoute);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }


    /**
     * 添加路线
     * @param patrolRoute
     * @return
     */
    @PostMapping("/addRoute")
    public CommonResult addRoute(@RequestBody PatrolRoute patrolRoute) {

        try {
            routeService.addRoute(patrolRoute);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }


    }


    /**
     *
     * 通过ID进行更新路线
     * @param patrolRoute
     * @return
     */
    @PutMapping("/UpdateRouteById/{id}")
    public CommonResult UpdateRouteById(@RequestBody PatrolRoute patrolRoute) {

        try {

            routeService.UpdateRouteById(patrolRoute);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }


    @DeleteMapping("/deleteRouteById")
    public CommonResult deleteRouteById(@RequestParam("id") Long id) {

        try {

            routeService.deleteRouteById(id);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }



    }




}
